
#ifndef SCOPE_H
#define SCOPE_H

#include "Object.h"
#include <vector>
#include <string>

namespace mjc {

	class SymbolTable;

	class Scope
	{
	private:
		static class ScopeData
		{
		public:
			ScopeData* outer;
			std::vector<Object> locals;//TODO: std::map<std::wstring, Object>
			ScopeData(): outer(NULL), locals(){}
			ScopeData(const ScopeData& sd);
			ScopeData& operator = (const ScopeData& sd);
			~ScopeData();
		};

		ScopeData* scopeData;
		int level;

	public:
		Scope();
		Scope(const Scope& other);
		Scope& operator = (const Scope& other);
		~Scope();
		void OpenScope();
		void CloseScope();
		int AddObject(Object& object);//returns 0 if object was added successfully, returns 1 if theres an object with the same name in locals vector
		Object* Find(const std::wstring& name);//returns a pointer to the object if it was found, otherwise returns NULL
		std::vector<Object>& GetLocals() { return scopeData->locals; }
		
		friend std::wostream& operator << (std::wostream& os, const Scope& scope);
	};
}

#endif